package com.leet.tree;

import java.util.LinkedList;
import java.util.Queue;

public class FindBottomLeftValue {
    public int findBottomLeftValue(TreeNode root) {
        int ans = 0;
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        while (!q.isEmpty()){
            int size = q.size();
            for(int i = 0 ; i < size; i++){
                TreeNode front = q.poll();
                if(i == 0){
                    ans = front.val;
                }
                if(front.left != null) q.offer(front.left);
                if(front.right != null) q.offer(front.right);
            }
        }
        return  ans;
    }
}
